#include "value.h"
#include <iostream>
#include <thread>

atomic<int> x(0);
atomic<int> y(0);
atomic<int> z(0);
atomic<bool> go(false);

void increment(atomic<int>* inc, struct value* val) {
	while (!go) {
		this_thread::yield();
	}
	for (unsigned int i = 0; i < count; i++) {
		val[i].x = x.load(memory_order_relaxed);
		val[i].y = y.load(memory_order_relaxed);
		val[i].z = z.load(memory_order_relaxed);
		inc->store(i+1, memory_order_relaxed);
		this_thread::yield();
	}
}

void readValues(struct value* val) {
	while (!go) {
		this_thread::yield();
	}
	for (unsigned int i = 0; i < count; i++) {
		val[i].x = x.load(memory_order_relaxed);
		val[i].y = y.load(memory_order_relaxed);
		val[i].z = z.load(memory_order_relaxed);
		this_thread::yield();
	}
}

void printValues(struct value* val) {
	for (unsigned int i = 0; i < count; i++) {
		if (i) {
			cout << ", ";
		}
		cout << "(" << val[i].x << ", " << val[i].y << ", "
			<< val[i].z << ")";
	}
	cout << endl;
}

